Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@turf/invariant

Package Overview
Dependencies
Maintainers
9
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@turf/invariant

turf invariant module

  • 7.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.5M
increased by5.97%
Maintainers
9
Weekly downloads
 
Created

What is @turf/invariant?

@turf/invariant is a module within the Turf.js library that provides utility functions for validating and extracting GeoJSON objects. It ensures that the input data conforms to the expected GeoJSON format, which is crucial for performing various geospatial operations.

What are @turf/invariant's main functionalities?

getCoord

The `getCoord` function extracts the coordinates from a GeoJSON Point feature. This is useful when you need to work directly with the coordinates of a point.

const turf = require('@turf/invariant');
const point = { type: 'Feature', geometry: { type: 'Point', coordinates: [102.0, 0.5] } };
const coord = turf.getCoord(point);
console.log(coord); // [102.0, 0.5]

getCoords

The `getCoords` function extracts the coordinates from a GeoJSON LineString or Polygon feature. This is useful for accessing the array of coordinates that make up the geometry.

const turf = require('@turf/invariant');
const line = { type: 'Feature', geometry: { type: 'LineString', coordinates: [[102.0, 0.0], [103.0, 1.0]] } };
const coords = turf.getCoords(line);
console.log(coords); // [[102.0, 0.0], [103.0, 1.0]]

getGeom

The `getGeom` function extracts the geometry object from a GeoJSON feature. This is useful when you need to work with the geometry independently of the feature properties.

const turf = require('@turf/invariant');
const feature = { type: 'Feature', geometry: { type: 'Polygon', coordinates: [[[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [102.0, 0.0]]] } };
const geom = turf.getGeom(feature);
console.log(geom); // { type: 'Polygon', coordinates: [[[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [102.0, 0.0]]] }

getType

The `getType` function returns the type of a GeoJSON object. This is useful for validating the type of geometry you are working with.

const turf = require('@turf/invariant');
const feature = { type: 'Feature', geometry: { type: 'Polygon', coordinates: [[[102.0, 0.0], [103.0, 1.0], [104.0, 0.0], [102.0, 0.0]]] } };
const type = turf.getType(feature);
console.log(type); // 'Polygon'

Other packages similar to @turf/invariant

Keywords

FAQs

Package last updated on 09 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc